package com.foreknow.demo12;

/**
 *  == 与 equals的区别
 *
 *  == 引用类型使用 == 比较的是内存地址
 *  equals 比较的是内容
 */
public class EqualsDemo {
    public static void main(String[] args) {
        String s1 = "haha";
        String s2 = "haha";
        String s3 = new String("haha");
        String s4 = new String("haha");
        String s5 = "ha"+"ha";
        String s6 = new String("ha") + "ha";

        Integer i1 = new Integer(10);
        Integer i2 = new Integer(10);
        System.out.println(i1 == i2); //false
        System.out.println(i1.equals(i2)); //true

        System.out.println(s1==s2);
        System.out.println(s1.equals(s2));
        System.out.println(s1==s3); //内存地址不同(new)
        System.out.println(s3==s4);
        System.out.println(s1==s5);
        System.out.println(s1==s6);
    }
}
